/*sig.c*/
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <wait.h>
#include <stdlib.h>
#include <sys/types.h>

void sigchld_handler(int sig) {
    int status;
    waitpid(-1, &status, WNOHANG); // 补充分号
    if (WIFEXITED(status)) 
        printf("child process exit normally\n");
    else if (WIFSIGNALED(status)) 
        printf("child process exit abnormally\n");
    else if (WIFSTOPPED(status)) 
        printf("child process is stopped\n");
    else 
        printf("else");
}

int main() {
    pid_t pid;
    signal(SIGCHLD, sigchld_handler);
    pid = fork();
    if (pid == 0) 
        abort(); // 修正 abort 调用
    else if (pid > 0) { 
        sleep(2); 
        printf("parent process\n"); 
    } else 
        exit(0);
    return 0; // 规范 main 函数返回
}

